package com.atguigu.gmall.order.receiver;


import com.atguigu.gmall.common.config.constant.MqCons;
import org.springframework.amqp.core.*;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.HashMap;
import java.util.Map;

@Configuration
public class OrderCanelMqConfig {


    @Bean
    public Queue cancelOrderQueue(){
        return QueueBuilder.durable(MqCons.QUEUE_ORDER_CANCEL).build();
    }
    @Bean
    public Queue closePaymentQueue(){
        return QueueBuilder.durable(MqCons.QUEUE_PAYMENT_CLOSE).build();
    }
    @Bean
    public CustomExchange cancelOrderExchange(){
        Map<String, Object> arguments = new HashMap<>();
        arguments.put("x-delayed-type","direct");
        return new CustomExchange(MqCons.EXCHANGE_DIRECT_ORDER_CANCEL,"x-delayed-message",true,false
        ,arguments);

    }
    @Bean
    public Binding cancelOrderBinding(){
        return BindingBuilder.bind(cancelOrderQueue())
                .to(cancelOrderExchange()).with(MqCons.ROUTING_ORDER_CANCEL).noargs();
    }
    @Bean
    public Binding closePaymentBinding(){
        return BindingBuilder.bind(closePaymentQueue())
                .to(cancelOrderExchange()).with(MqCons.ROUTING_ORDER_CANCEL).noargs();
    }

}
